<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>售后管理系统登录</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
	<jsp:include page="resource_path.jsp" flush="true"/>
</head>
<body class="login-bg">
    <div class="login layui-anim layui-anim-up">
        <div class="message">售后管理系统注册</div>
        <div id="darkbannerwrap">
        </div>
        <form class="layui-form" method="post" id="addform">
            <input name="userAccount" onfocus="editValue()" id="userAccount"  placeholder="账号"  type="text" lay-verify="userAccount" class="layui-input" >
            <hr class="hr15">
            <input name="userName" id="userName"  placeholder="姓名"  type="text" lay-verify="userName" class="layui-input" >
            <hr class="hr15">
            <input name="password" id="password" lay-verify="password" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">
            <input name="phone" id="phone" lay-verify="phone" placeholder="电话号码"  type="text" class="layui-input">
            <hr class="hr15">
            <div class="layui-form-item">
    		<label class="layui-form-label">性别</label>
    		<div class="layui-input-block">
      		<input type="radio" name="sex" value="1" title="男" checked="">
      		<input type="radio" name="sex" value="1" title="女">
   			</div>
  			</div>
  			<input type="checkbox" lay-filter="iAgree" lay-skin="primary" title="我同意"  > <a href="#">《点击查看协议内容》</a>
  			<hr class="hr20" >
           <input type="button" value="注册" id="submit" style="width:100%;background:#666" lay-submit lay-filter="addform" disabled="true" >
            <hr class="hr20" >
            <div id="hhang" style="width: 100%; height: 30px"></div>  
          <input type="button" value="已有账号  前往登录" <%--lay-submit lay-filter="login" --%>style="width:100%;" onclick="tologin()">
        </form>

    </div>
    
     <script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
	<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
    
    <script>
        function tologin() {
            window.location.href = "${pageContext.request.contextPath }/login.jsp"
        }

        layui.use(['form'], function(){
        	var form = layui.form;
        	  form.verify({
                  userAccount:function (value,item){
                      if(""==value.replace(/\s+/g,"")){
                          return '账号不能为空';
                      }
                  },
                  userName:function(value,item){
                      if(""==value.replace(/\s+/g,"")){
                          return '姓名不能为空';
                      }
                  },
                  password:function(value,item){
                      if(""==value.replace(/\s+/g,"")){
                          return '密码不能为空';
                      }
                  },
              });
        	  form.on('checkbox(iAgree)', function(data){
        		var checked = data.elem.checked;
        		 if(checked==false){
        			 $('#submit').attr("disabled",false);
        			 $('#submit').attr("style","width:100%;background:#189F92")
        		 }else{
        		 	$('#submit').attr("disabled",true);
        		 	 $('#submit').attr("style","width:100%;background:#666")
        		 }
        		 
        		}); 
        	 
        	  form.on('submit(addform)', function (data) {
        		  $("#submit").attr("disabled",true);
                  $.ajax({
                      type: "post",
                      url: "${pageContext.request.contextPath }/user/register.do",
                      data: $("#addform").serialize(),
                      dataType: "json",
                      success: function(data){
                          //console.log(data.message);
                          //var obj  = eval('(' + data + ')');
                          //alert(obj);
                          if(data.data==true) {
                        		layer.msg("注册成功！");
                              setTimeout(function (){
                                  window.location.href = "${pageContext.request.contextPath }/login.jsp"
                              }, 1000);
                          }else {
                        	  layer.msg(data.message);
                          }
                      }
                  });
        		  
        	 	 });
        })
      
function editValue(){
	$("#submit").attr("disabled",false);
	
}
        
$('#userAccount').blur(function(){
	var userAccount =$("#userAccount").val();
	var suID ='';
	if(""==value.replace(/\s+/g,"")){
		layer.msg("账号不能为空");	
	}else{
		$.ajax({
			url : '${pageContext.request.contextPath }/sysUser/isHaveUser.do',
				data : {'userAccount':userAccount,
						'suID':suID},
				type : "post",
				//dataType : "json",
			}).done(function(res){
				if(res==-1){
					layer.msg("该账号已存在，请重新输入！")
					$("#submit").attr("disabled",true);
				}
			})
			.fail(function(res){
				layer.msg("检测用户账号失败，服务器错误");
			})
			return false;
		}
	});
       
    </script>
</body>
</html>